<h3>Sản phẩm tìm thấy</h3>
<?php
	
	if(isset($_POST['TimKiem']))
	{
		$tkhoa = $_POST['key'];
		$loai  = $_POST['loai'];
		$sanpham = new sanphambs();
		
		if($loai == 0)
		$sanpham->loai = 0;
		else if($loai == 1)
		$sanpham->loai = 1;
		else if($loai == 2)
		$sanpham->loai = 2;
		else if($loai == 3)
		$sanpham->loai = 3;
		else if($loai == 4)
		$sanpham->loai = 4;
		else if($loai == 5)
		$sanpham->loai = 5;
		else if($loai == 6)
		$sanpham->loai = 6;
		else if($loai == 7)
		$sanpham->loai = 7;
		$sanpham->key = $tkhoa;
		$dssanpham = $sanpham->Find();
		if($dssanpham)
		{
			$tongsodong = count($dssanpham);
			if($tongsodong>0)
			{
			if(!isset($_GET['start']))
				$start = 0;
			else
				$start = $_GET['start'];
				$limit = 5;
				$next = $start + $limit;
				$back = $start - $limit;
				$danhsach = $sanpham->DS_Find($start, $limit);
			for($i = 0; $i < ($danhsach == false ? 0 : count($danhsach)) ; $i++)
			{
				if($danhsach[$i]['SoLuong']>0)
				{
					echo "<div id='SanPham'>";
						$hinhanh = new hinhanhbs();
						$hinhanh->MaSanPham = $danhsach[$i]['MaSanPham'];
						$dshinh = $hinhanh->GetList();
						echo "<a href='index.php?do=chitietsanpham&msp={$danhsach[$i]['MaSanPham']}'><img src='{$dshinh[0]['patch']}' /> </a>";
						echo "<p class='TenSanPham'>{$danhsach[$i]['TenSanPham']}</p>";
						echo "<p>Nhà sản xuất: {$danhsach[$i]['TenNhaSX']}</p>";
						echo "<p>Chất liệu: {$danhsach[$i]['TenChatLieu']}</p>";
						echo "<p>Giá bán: <span class='GiaBan'>" . number_format($danhsach[$i]['DonGia']) . " VNĐ</span></p>";
						echo "<p class='DatMua'><a href='index.php?do=giohang&id={$danhsach[$i]['MaSanPham']}'>Đặt mua</a></p>";
					echo "</div>";
				}
			}	
			}
		}
		else
		{
			echo "<p>Không tìm thấy thấy kết quả nào!</p>";
		}
	}
?>
<?php
			if($tongsodong > $limit)
			{
				echo "<div id='PhanTrang' align = 'center'>";
					if($start > 0)
						echo "<a href='home_timkiem&start=$back'>Trang trước</a>&nbsp;";
					
					$j = 1;
					for($i = 0; $i < $tongsodong; $i += $limit)
					{
						if($i == $start)
							echo "<span style='color:#ff0000;font-weight:bold;'>" . $j . "</span>&nbsp;";
						else
							echo "<a href='home_timkiem&start=$i'>" . $j . "</a>&nbsp;";
						
						$j++;
					}
					
					if($start + $limit < $tongsodong)
						echo "<a href='home_timkiem&start=$next'>Trang sau</a>";
				echo "</div>";
				echo "<br/>";
			}
?>